﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MaxStudio.Concrete.DBUtility;
using MaxStudio.Concrete.Server.Dao;
using MaxStudio.Concrete.Server.Interface;

namespace MaxStudio.Concrete.Server.Service
{
    public class RPTScrapConcreteService : ServiceHandle, IScrapConcrete
    {
        #region IScrapConcrete Members

        public OperationResult<List<tb_RPT_ScrapConcrete>> GetAllScrapConcrete()
        {
            OperationResult<List<tb_RPT_ScrapConcrete>> result = new OperationResult<List<tb_RPT_ScrapConcrete>>();
            List<tb_RPT_ScrapConcrete> list = new List<tb_RPT_ScrapConcrete>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetAllScrapConcrete();
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_ScrapConcrete>> GetScrapConcreteByInputDate(DateTime inputdate)
        {
            OperationResult<List<tb_RPT_ScrapConcrete>> result = new OperationResult<List<tb_RPT_ScrapConcrete>>();
            List<tb_RPT_ScrapConcrete> list = new List<tb_RPT_ScrapConcrete>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetScrapConcreteByInputDate(inputdate);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_ScrapConcrete>> GetScrapConcreteByInputDate(DateTime inputdate1, DateTime inputdate2)
        {
            OperationResult<List<tb_RPT_ScrapConcrete>> result = new OperationResult<List<tb_RPT_ScrapConcrete>>();
            List<tb_RPT_ScrapConcrete> list = new List<tb_RPT_ScrapConcrete>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetScrapConcreteByInputDate(inputdate1, inputdate2);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_ScrapConcrete>> GetScrapConcreteByContition(string strWeather, string strProjectName, string strInputDate, string strConstructionUnit, string strConstructionSite, string strIntensityLevel, string strDevelopmentTime, string strQuantity, string strCement, string strProductLine, string strApproachTo, string strCarryOn)
        {
            OperationResult<List<tb_RPT_ScrapConcrete>> result = new OperationResult<List<tb_RPT_ScrapConcrete>>();
            List<tb_RPT_ScrapConcrete> list = new List<tb_RPT_ScrapConcrete>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetScrapConcreteByContition(strWeather, strProjectName, strInputDate, strConstructionUnit, strConstructionSite, strIntensityLevel, strDevelopmentTime, strQuantity, strCement, strProductLine, strApproachTo, strCarryOn);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_ScrapConcrete>> GetScrapConcreteByProjectName(string strProjectName)
        {
            OperationResult<List<tb_RPT_ScrapConcrete>> result = new OperationResult<List<tb_RPT_ScrapConcrete>>();
            List<tb_RPT_ScrapConcrete> list = new List<tb_RPT_ScrapConcrete>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetScrapConcreteByProjectName(strProjectName);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_ScrapConcrete> GetScrapConcreteById(int id)
        {
            ConcreteDaoDataContext dataContext = getDateContext();
            OperationResult<tb_RPT_ScrapConcrete> result = new OperationResult<tb_RPT_ScrapConcrete>();
            tb_RPT_ScrapConcrete scrapConcrete;
            try
            {
                scrapConcrete = dataContext.GetScrapConcreteById(id);
                if (scrapConcrete == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = scrapConcrete;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_ScrapConcrete> CreateScrapConcrete(tb_RPT_ScrapConcrete entity)
        {
            OperationResult<tb_RPT_ScrapConcrete> result = new OperationResult<tb_RPT_ScrapConcrete>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.CreateScrapConcrete(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_ScrapConcrete> ModifyScrapConcrete(tb_RPT_ScrapConcrete entity)
        {
            OperationResult<tb_RPT_ScrapConcrete> result = new OperationResult<tb_RPT_ScrapConcrete>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.ModifyScrapConcrete(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_ScrapConcrete> DeleteScrapConcrete(tb_RPT_ScrapConcrete entity)
        {
            OperationResult<tb_RPT_ScrapConcrete> result = new OperationResult<tb_RPT_ScrapConcrete>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.DeleteScrapConcrete(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        #endregion
    }
}
